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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0])
t = pylab.ifft(f)

def mycorrelate(x0, x1, mode='full'):
    length0 = len(x0)
    length1 = len(x1) 
    x2 = numpy.conjugate(x1)
    total = length1+length0
    output = [0]*total
    for i in range(total):
        sum = 0
        if i > length1:
            number_of_overlap = length1*2-i
        else:
            number_of_overlap = i
        for j in range(number_of_overlap):
            #print 'i is %d, j is %d, number_of_overlap is %d'%(i,j,number_of_overlap)
            sum += x0[j]*x2[length1-number_of_overlap+j]
        output[i] = sum
    return output

#barker = [1,1,1,1,1,-1,-1,1,1,-1,1,-1,1]
#bx = mycorrelate(barker,barker, mode='full')
#pylab.plot(bx, 'g')
#pylab.figure()

pylab.plot(range(1024), numpy.real(t),'g.',range(1024),numpy.imag(t),'b.')
pylab.figure()
pylab.plot(range(1024), numpy.real(f),'g.',range(1024),numpy.imag(f),'b.')
pylab.figure()
#xf = numpy.correlate(f, f, mode='full')
xf = numpy.correlate(f, f, mode='full')
pylab.plot(numpy.abs(xf),'g')
pylab.figure()
#xt = numpy.correlate(t, t, mode='full')
xt = numpy.correlate(t, numpy.conjugate(t), mode='full')
pylab.plot(numpy.abs(xt),'g')
pylab.show()
